//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#include <algorithm>
#include <common/range.h>
#include "randomdouble.h"
//
namespace model
{
RandomDouble::Constant::Constant(double p_value)
:
   Data(type_constant),
   value(p_value)
{
}
double RandomDouble::Constant::get_value()const
{
   return value;
}
void RandomDouble::Constant::set_value(double p_value)
{
   value=p_value;
}
double RandomDouble::Constant::calculate(double p_phase)const
{
   return value;
}
Range RandomDouble::Constant::get_range()const
{
   return Range(value);
}
MultiTypeData *RandomDouble::Constant::clone()const
{
   return new Constant(value);
}
void RandomDouble::Constant::store(QDataStream &p_stream)const
{
   p_stream<<value;
}
void RandomDouble::Constant::restore(QDataStream &p_stream)
{
   p_stream>>value;
}
//
RandomDouble::Interval::Interval(double p_min,double p_max)
:
   Data(type_interval),
   min(p_min),max(p_max)
{
}
double RandomDouble::Interval::get_min()const
{
   return min;
}
void RandomDouble::Interval::set_min(double p_min)
{
   min=p_min;
}
double RandomDouble::Interval::get_max()const
{
   return max;
}
void RandomDouble::Interval::set_max(double p_max)
{
   max=p_max;
}
double RandomDouble::Interval::calculate(double p_phase)const
{
   return qrand_interval<double>(min,max);
}
Range RandomDouble::Interval::get_range()const
{
   double min_=min,max_=max;
   if(min_>max_)
      std::swap(min_,max_);
   return Range(min_,max_);
}
MultiTypeData *RandomDouble::Interval::clone()const
{
   return new Interval(min,max);
}
void RandomDouble::Interval::store(QDataStream &p_stream)const
{
   p_stream<<min<<max;
}
void RandomDouble::Interval::restore(QDataStream &p_stream)
{
   p_stream>>min>>max;
}
}
